package restructure.chapter06;

import java.util.Arrays;
import java.util.List;

/**
 * 6.9替代算法
 */
public class SubstituteAlgorithm {

    String findPerson(String[] people) {
        for (String person : people) {
            if (person.equals("Don")) {
                return "Don";
            }
            if (person.equals("John")) {
                return "John";
            }
            if (person.equals("Kent")) {
                return "Kent";
            }
        }
        return "";
    }

    String findPerson_(String[] people) {
        List<String> candidates = Arrays.asList("Don", "John", "Kent");
        for (String person : people) {
            if (candidates.contains(person))
                return person;
        }
        return "";
    }
}
